package com.own.component.util.excel.util.read.config;

import com.own.component.util.excel.util.read.base.BaseExcelReadConfig;
import com.own.component.util.excel.util.read.method.RowMethod;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.poi.ss.usermodel.Row;

import java.io.Serializable;
import java.util.List;
import java.util.function.Function;

/**
 * ExcelReadLineConfig
 *
 * @author chenxueli
 * @date 2022-10-10 10:36:00
 */
@Getter
@Setter
@Accessors(chain = true)
public class ExcelReadLineConfig<T> extends BaseExcelReadConfig<T> implements Serializable {

    /**
     * 读取所有行的参数
     */
    private static final int ALL_READ = Integer.MAX_VALUE;

    /**
     * 字段标记的行数
     */
    private int fieldLine;

    /**
     * 数据开始的行数
     */
    private int dataLine;

    /**
     * 读取的行数（0的时候为全部）
     */
    private int readLine;

    /**
     * 获取字段的方法
     */
    private Function<Row, List<String>> fieldMethod;

    public ExcelReadLineConfig() {
        this.fieldLine = 2;
        this.dataLine = 3;
        this.readLine = ALL_READ;

        // 默认为获取批注信息
        fieldUseCellComment();
    }

    /**
     * 字段值使用单元格信息
     *
     * @return this
     */
    public ExcelReadLineConfig<T> fieldUseCellValue() {
        this.fieldMethod = item -> RowMethod.listRowValue(item, this);
        return this;
    }

    /**
     * 字段值使用备注信息
     *
     * @return this
     */
    public ExcelReadLineConfig<T> fieldUseCellComment() {
        this.fieldMethod = item -> RowMethod.listRowComment(item, this);
        return this;
    }

}
